using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Filters;
using ZR.Model.Dto.Business.ProductionControl;
using ZR.Model.Models.ProductionControl;
using ZR.Service.IService.ProductionControl;

namespace ZR.Admin.WebApi.Controllers
{
    /// <summary>
    /// 设备配方管理
    /// </summary>
    [Verify]
    [Route("business/RecipeConfig")]
    [ApiExplorerSettings(GroupName = "business")]

    public class RecipeConfigController : BaseController
    {
        /// <summary>
        /// 设备配方管理接口
        /// </summary>
        private readonly IRecipeConfigService _RecipeConfigService;

        public RecipeConfigController(IRecipeConfigService RecipeConfigService)
        {
            _RecipeConfigService = RecipeConfigService;
        }

        /// <summary>
        /// 查询设备配方管理列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "recipeconfig:list")]
        public IActionResult QueryRecipeConfig([FromQuery] RecipeConfigQueryDto parm)
        {
            var response = _RecipeConfigService.GetList(parm);
            return SUCCESS(response);
        }

        /// <summary>
        /// 查询设备配方管理详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "recipeconfig:query")]
        public IActionResult GetRecipeConfig(int Id)
        {
            var response = _RecipeConfigService.GetInfo(Id);

            var info = response.Adapt<RecipeConfigDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加设备配方管理
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "recipeconfig:add")]
        [Log(Title = "设备配方添加", BusinessType = BusinessType.INSERT)]
        public IActionResult AddRecipeConfig([FromBody] RecipeConfigDto parm)
        {
            var modal = parm.Adapt<RecipeConfig>().ToCreate(HttpContext);

            var response = _RecipeConfigService.AddRecipeConfig(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新设备配方管理
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "recipeconfig:edit")]
        [Log(Title = "设备配方更新", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateRecipeConfig([FromBody] RecipeConfigDto parm)
        {
            var modal = parm.Adapt<RecipeConfig>().ToUpdate(HttpContext);
            var response = _RecipeConfigService.UpdateRecipeConfig(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除设备配方管理
        /// </summary>
        /// <returns></returns>
        [HttpDelete("delete/{ids}")]
        [ActionPermissionFilter(Permission = "recipeconfig:delete")]
        [Log(Title = "设备配方删除", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteRecipeConfig([FromRoute] string ids)
        {
            var idArr = Tools.SplitAndConvert<int>(ids);

            return ToResponse(_RecipeConfigService.Delete(idArr));
        }
    }
}